package com.l.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;

@Configuration
@ConfigurationProperties(prefix = "my-es")
public class ESConfig {


    private String host;
    private int port;


    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

//    @Bean
    public RestHighLevelClient client(){
//        return new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.46.128:9200")));
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port)));
    }
}
